package com.huawei.hianalytics.ab.bc.ik.bc;

import android.content.Context;
import com.huawei.hianalytics.ab.ab.cd;
import com.huawei.hianalytics.ab.bc.cd.bc.de;
import com.huawei.hianalytics.ab.bc.ik.cd.ab;
import com.huawei.hianalytics.ab.bc.kl.ef;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class bc implements ab {
    private Context ab = com.huawei.hianalytics.ab.ab.bc.ik();
    private String bc;
    private JSONObject cd;
    private String de;
    private String ef;
    private String fg;
    private String gh;
    private Boolean hi;

    public bc(String str, JSONObject jSONObject, String str2, String str3, long j) {
        this.bc = str;
        this.cd = jSONObject;
        this.de = str2;
        this.ef = str3;
        this.fg = String.valueOf(j);
        if (com.huawei.hianalytics.ab.ab.ab.ef(str2, "oper")) {
            com.huawei.hianalytics.ab.bc.hi.bc ab = com.huawei.hianalytics.ab.bc.hi.ab.ab().ab(str2, j);
            this.gh = ab.ab();
            this.hi = Boolean.valueOf(ab.bc());
        }
    }

    public void run() {
        com.huawei.hianalytics.ab.bc.ef.ab.bc("EventRecordTask", "Begin to run EventRecordTask...");
        int hi = com.huawei.hianalytics.ab.ab.bc.hi();
        int hi2 = cd.hi(this.de, this.ef);
        if (com.huawei.hianalytics.ab.bc.kl.bc.ab(this.ab, "stat_v2_1", hi * 1048576)) {
            com.huawei.hianalytics.ab.bc.ef.ab.bc("hmsSdk", "stat sp file reach max limited size, discard new event");
            com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab("", "alltype");
            return;
        }
        de deVar = new de();
        deVar.bc(this.bc);
        deVar.cd(this.cd.toString());
        deVar.ab(this.ef);
        deVar.de(this.fg);
        deVar.ef(this.gh);
        deVar.fg(this.hi == null ? null : String.valueOf(this.hi));
        try {
            JSONArray jSONArray;
            JSONObject de = deVar.de();
            String ab = ef.ab(this.de, this.ef);
            try {
                jSONArray = new JSONArray(com.huawei.hianalytics.ab.bc.ij.ab.bc(this.ab, "stat_v2_1", ab, ""));
            } catch (JSONException e) {
                com.huawei.hianalytics.ab.bc.ef.ab.bc("EventRecordTask", "Cached data corrupted: stat_v2_1");
                jSONArray = new JSONArray();
            }
            jSONArray.put(de);
            com.huawei.hianalytics.ab.bc.ij.ab.ab(this.ab, "stat_v2_1", ab, jSONArray.toString());
            if (jSONArray.toString().length() > hi2 * WXMediaMessage.DESCRIPTION_LENGTH_LIMIT) {
                com.huawei.hianalytics.ab.bc.ik.ab.ab.ab().ab(this.de, this.ef);
            }
        } catch (JSONException e2) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("EventRecordTask", "eventRecord toJson error! The record failed.");
        }
    }
}
